import React, { useEffect } from "react";
import { Button, Form, Input } from "antd";
const formtype = (props) => {
  const [form] = Form.useForm();

  useEffect(() => {
    if (props.title == "编辑") {
      form.setFieldsValue(props.objItem);
    }
  }, []);

  const onFinish = async (values: any) => {
    console.log(values);
    if (props.title == "添加") {
      let obj = {
        id: new Date().getTime(),
        ...values,
      };
      props.onCancel(obj);
    } else {
      let obj = {
        ...props.objItem,
        ...values,
        time: new Date().getTime(),
      };
      props.onOk(obj);
    }
  };

  return (
    <Form onFinish={onFinish} style={{ maxWidth: 600 }} form={form}>
      <Form.Item
        label="关联订单"
        name="name"
        rules={[
          {
            required: true,
            message: "请输入关联订单!",
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        label="订单归属人"
        name="stage"
        rules={[
          {
            required: true,
            message: "请输入订单归属人!",
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        label="回款期次"
        name="bjnum"
        rules={[
          {
            required: true,
            message: "请输入回款期次!",
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        label="计划回款金额"
        name="price"
        rules={[
          {
            required: true,
            message: "请输入计划回款金额!",
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        label="已回款金额"
        name="Customer"
        rules={[
          {
            required: true,
            message: "请输入已回款金额!",
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        label="计划回款日期"
        name="time"
        rules={[
          {
            required: true,
            message: "请输入计划回款日期!",
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        label="回款状态"
        name="days"
        rules={[
          {
            required: true,
            message: "请输入回款状态!",
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item>
        <Button type="primary" htmlType="submit">
          确定
        </Button>
      </Form.Item>
    </Form>
  );
};

export default formtype;
